import { AxiosResponse } from 'axios'
import { service, baseURL } from './config'


/* ***********************************用户相关*********************************** */
// 获取服务器内所有的用户---分页展示
export function getAllUser(page: number, pageSize: number) {
    return service.get('/user/getAllUser', { params: { page, pageSize } })
}

// 用户注册是否重名
export function checkUserName(username: string): Promise<AxiosResponse<any, any>> {
    return service.get('/user/check_rename', { params: { username } })
}
// 获取用户所有信息
export function refreshUserAllInfo(): Promise<AxiosResponse<any, any>> {
    return service.get('/user/refreshUserInfo')
}


// 用户注册
export function registerUser(username: string, password: string): Promise<AxiosResponse<any, any>> {
    return service.post('/user/register', { username, password })
}
// 用户登录
export function loginUser(username: string, password: string): Promise<AxiosResponse<any, any>> {
    return service.post('/user/login', { username, password })
}


// 更新用户客户端IP信息
export function updateUserIpInfo(ip: string) {
    return service.put('/user/updateUserIpInfo', { ip })
}
// 更新用户客户端设备信息
export function updateUserClientInfo(client: string) {
    return service.put('/user/updateUserClientInfo', { client })
}
// 更新用户等级
export function updateUserLevel(playTime: number) {
    return service.put('/user/updateUserLevel', { playTime })
}
// 更新用户信息
export function updateUserInfo(_id: string, field: string, updata: any[] | string | boolean | number) {
    return service.put('/user/updateUserInfo', { _id, field, updata })
}

/* ***********************************音频相关*********************************** */
// 获取服务器内所有的音频---分页展示
export function getAllAudio(page: number, pageSize: number) {
    return service.get('/music/getAllAudio', { params: { page, pageSize } })
}

// 搜索服务器内的音乐
export function searchAudio(searchValue: string, page: number, pageSize: number): Promise<AxiosResponse<any, any>> {
    return service.get('/music/searchAudio', { params: { searchValue, page, pageSize } })
}
// 喜欢这个音频
export function likeItAudio(_id: string, method: string, index?: number) {
    return service.get('/music/likeItAudio', { params: { _id, method, index } })
}

// 更新音频tag标签
export function updateAudioInfo(_id: string, field: string, updata: any[] | string | boolean | number) {
    return service.put('/music/updateAudioInfo', { _id, field, updata })
}


// 不喜欢这个音频
export function dontLikeItAudio(_id: string) {
    return service.delete('/music/dontLikeItAudio', { params: { _id } })
}
// 不喜欢这个音频
export function deleteAudio(_id: string) {
    return service.delete('/music/deleteAudio', { params: { _id } })
}



export const baseUrl = baseURL
// 音频上传地址
export const uploadAudio = baseURL + '/music/uploadAudio'
// 音频封面上传地址
export const uploadAudioCover = baseURL + '/cover/uploadAudioCover'
// 音频歌词上传地址
export const uploadAudioLyric = baseURL + '/lyric/uploadAudioLyric'